/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ec.socialfun.servicios;

import com.ec.socialfun.entidades.EventosInteres;
import com.ec.socialfun.enumeradores.EstadoEnum;
import com.ec.socialfun.excepciones.RecuperaEventoInteresException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.jboss.logging.Logger;

/**
 *
 * @author jorge
 */
@Stateless
public class EventosInteresFacade extends AbstractFacade<EventosInteres> {

    private static final Logger LOG = Logger.getLogger(EventosInteresFacade.class.getName());
    @PersistenceContext(unitName = "SocialFunPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public EventosInteresFacade() {
        super(EventosInteres.class);
    }

    /**
     * recupera el evento interes que se encuentra vigente
     *
     * @return
     * @throws RecuperaEventoInteresException
     */
    public EventosInteres recuperaEventoInteresVigente() throws RecuperaEventoInteresException {
        try {
            Query q = em.createNamedQuery("EventosInteres.findByEvInEstado");
            q.setParameter("evInEstado", EstadoEnum.ACTIVO.getCodigo());
            return (EventosInteres) q.getSingleResult();
        } catch (Exception e) {
            LOG.error("Error al recuperar evento interes vigente " + e);
            throw new RecuperaEventoInteresException("Error al recuperar evento interes vigente ");
        }

    }
}
